<%--                                                                       --%>
<%-- Copyright (c) 2004-2005 BroadVision, Inc.  All rights reserved.       --%>
<%--                                                                       --%>
<%-- This software is copyrighted. Under the copyright laws, this software --%>
<%-- may not be copied, in whole or in part, without prior written consent --%>
<%-- of BroadVision, Inc. or its assignees. This software is provided      --%>
<%-- under the terms of a license between BroadVision and the recipient,   --%>
<%-- and its use is subject to the terms of that license.                  --%>
<%--                                                                       --%>
<%-- This software may be protected by one or more U.S. and International  --%>
<%-- patents.  Certain applications of BroadVision One-To-One software are --%>
<%-- covered by U.S. patent 5,710,887.                                     --%>
<%--                                                                       --%>
<%-- TRADEMARKS: BroadVision and BroadVision One-To-One are registered     --%>
<%-- trademarks of BroadVision, Inc., in the United States and the         --%>
<%-- European Community, and are trademarks of BroadVision, Inc., in other --%>
<%-- countries.  The BroadVision logo, is a trademark of BroadVision,      --%>
<%-- Inc., in the United States and other countries. Additionally, IONA    --%>
<%-- and Orbix are trademarks of IONA Technologies, Ltd.  RSA, MD5, and    --%>
<%-- RC2 are trademarks of RSA Data Security, Inc.                         --%>
<%--                                                                       --%>

<%@ taglib uri="/WEB-INF/c.tld" prefix="c" %>
<%@ taglib uri="/WEB-INF/struts-html-el.tld" prefix="html-el" %>
<%@ taglib uri="/WEB-INF/struts-bean-el.tld" prefix="bean-el" %>
<%@ taglib uri="/WEB-INF/struts-bean.tld" prefix="bean" %>

<script language="JavaScript">

//
//
//
function doChannelSelect() {
  doPickerPopupAction('<c:url value="/mt/categoryPickerPopup.do"/>', 'setParentChannel', 
    301, null, null, null, null, null, null, null, null, null, false);
}

//
//
//
function setParentChannel(ids, names) {
  document.epChannelForm.parentId.value = ids[0];
  document.epChannelForm.parentName.value = names[0];
}

//
//
//
function selectJspPopup() {
  jspScriptPickerPopup('setSelectedJsp');
}
  
//
//
//
function setSelectedJsp(jspPath) {
  document.epChannelForm.scriptPath.value = jspPath;
}

//
//
//
function doCancel(form) {
  form.action = "<c:url value="/ep/cancel.do"/>";
  form.submit();
}

//
//
//
function validateStartType(form) {
  var scriptPath = form.scriptPath.value;
  scriptPath = scriptPath.stringTrim();
  form.scriptPath.value = scriptPath;

  var urlPath = form.urlPath.value;
  urlPath = urlPath.stringTrim();
  form.urlPath.value = urlPath;

  for (var index = 0; index < form.startType.length; index++) {
    if (form.startType[index].checked) {
      var startType = form.startType[index].value;
      if (startType == 0) {  // Script
        if (scriptPath == "") {
          <c:set var="argName"><bean-el:message key="ep.channel.startType.script" bundle="ep.messages"/></c:set>
          alert("<bean-el:message key="errors.required" arg0="${argName}"/>");
          form.scriptPath.focus();
          return false;
        }
      }
      if (startType == 1) {  // URL
        if (urlPath == "") {
          <c:set var="argName"><bean-el:message key="ep.channel.startType.url" bundle="ep.messages"/></c:set>
          alert("<bean-el:message key="errors.required" arg0="${argName}"/>");
          form.urlPath.focus();
          return false;
        }
      }
    }
  }
  return true;
}

//
//
//
function validateParentType(form) {
  for (var index = 0; index < form.parentType.length; index++) {
    if (form.parentType[index].checked) {
      var parentType = form.parentType[index].value;
      if (parentType == 1) {
        var parentId = form.parentId.value;
        if (parentId == "" || parentId == 0) {
          alert("<bean-el:message key="ep.channel.parent.channel.required" bundle="ep.messages"/>");
          return false;
        }
      }
    }
  }
  return true;
}

//
//
//
function validateForm(form) {
  var name = form.name.value;
  form.name.value = name.stringTrim();

  if (!validate(form)) return false;

  if (!validateStartType(form)) return false;

  if (!validateParentType(form)) return false;

  return true;
}

//
//
//
function disableBrowseScript(disable) {
  document.epChannelForm.btnBrowseScript.disabled = disable;
}

//
//
//
function disableBrowseChannel(disable) {
  document.epChannelForm.btnBrowseChannel.disabled = disable;
}

</script>

<%@include file="/mt/common/pickerPopupHelper.jsp" %>

<%@include file="/ep/file/jspScriptPickerHelper.jsp" %>

<html-el:javascript formName="epChannelForm" method="validate"/>

<table class="zoneFive" width="100%" border="0" cellspacing="0" cellpadding="0" summary="content area">
  <tr>
    <td valign="top" width="100%">
      <div class="pageTitle">
      <c:if test="${epChannelForm.map.id == 0}">
        <bean-el:message key="ep.channel.new.page.title" bundle="ep.messages"/>
      </c:if>
      <c:if test="${epChannelForm.map.id != 0}">
        <bean-el:message key="ep.channel.edit.page.title" bundle="ep.messages" arg0="${epChannelEditView.map.name}"/>
      </c:if>
      </div>
      <div class="errorMessage"><html-el:errors bundle="ep.messages"/></div>
      <%@ include file="/mc/common/pagetab.jsp" %>

      <div class="breadcrumb">
      <c:if test="${not empty epChannelEditView.map.breadcrumbs}">
        <bean:size id="len" name="epChannelEditView" property="breadcrumbs"/>
        <c:forEach var="channel" items="${epChannelEditView.map.breadcrumbs}" varStatus="index">
          <c:url var="browseUrl" value="/ep/channelBrowse.do">
            <c:param name="channelId" value="${channel.map.id}"/>
          </c:url>
          <c:if test="${index.count > 1}"><bean-el:message key="ep.breadcrumb.delimiter" bundle="ep.messages"/></c:if>&nbsp;<c:if test="${index.count != len}"><!--a href="<c:out value="${browseUrl}"/>"--></c:if><c:out value="${channel.map.name}"/><c:if test="${index.count != len}"><!--/a--></c:if>
        </c:forEach>
      </c:if>
      </div>

      <!- place body here -->

      <html-el:form action="/ep/channelSave.do" focus="name" onsubmit="return validateForm(this);">

      <html-el:hidden property="channelId" value="${epChannelForm.map.id}"/>
      <html-el:hidden property="parentId"/>
      <input type="hidden" name="ctx.f" value="<c:out value="${requestScope['ctx.f']}"/>"/>

      <div class="pageSubtitle">
        <span class="left"><bean-el:message key="ep.channel.information" bundle="ep.messages"/></span>
        <span class="right">&nbsp;</span>
      </div>

      <table class="labelForm" width="100%" border="0" cellspacing="0" cellpadding="0">
      <tr>
        <td class="label"><bean-el:message key="ep.channel.name" bundle="ep.messages"/>:*</td>
        <td class="labelField"><html-el:text property="name" size="50" maxlength="80"/>
        </td>
      </tr>

      <tr>
        <td class="label"><bean-el:message key="ep.channel.display" bundle="ep.messages"/>:*</td>
        <td class="labelField">
          <table border="0" cellspacing="0" cellpadding="0" width="100%" summary="Channel display options">
          <tr>
            <td class="labelField"><html-el:radio property="startType" value="2" onclick="disableBrowseScript(true)"/><bean-el:message key="ep.channel.startType.display.template" bundle="ep.messages"/></td>
            <td class="labelField" align="left">
<c:if test="${not empty epChannelEditView.map.displayTemplates}">
              <html-el:select property="displayTemplateId">
  <c:forEach var="template" items="${epChannelEditView.map.displayTemplates}">
              <html-el:option value="${template.map.id}"><c:out value="${template.map.name}"/></html-el:option>
  </c:forEach>
              </html-el:select>
</c:if>
            </td>
          </tr>
<c:set var="btnDisabled" value=""/>
<c:if test="${epChannelForm.map.startType != 0}">
  <c:set var="btnDisabled">disabled="disabled"</c:set>
</c:if>
          <tr>
            <td class="labelField"><html-el:radio property="startType" value="0" onclick="disableBrowseScript(false)"/><bean-el:message key="ep.channel.startType.script" bundle="ep.messages"/></td>
            <td class="labelField" align="left"><html-el:text property="scriptPath" size="35" maxlength="255"/>&nbsp;<input type="button" name="btnBrowseScript" class="pageButton" value="<bean-el:message key="button.browse" bundle="ep.messages"/>" onclick="selectJspPopup()" <c:out value="${btnDisabled}"/>></td>
          </tr>
          <tr>
            <td class="labelField"><html-el:radio property="startType" value="1" onclick="disableBrowseScript(true)"/><bean-el:message key="ep.channel.startType.url" bundle="ep.messages"/></td>
            <td class="labelField" align="left"><html-el:text property="urlPath" size="35" maxlength="255"/></td>
          </tr>
          </table>
        </td>
      </tr>

      <tr>
        <td class="label"><bean-el:message key="ep.description" bundle="ep.messages"/>:</td>
        <td class="labelField"><html-el:textarea property="description" rows="5" cols="50"/>
        </td>
      </tr>

      <tr>
        <td class="label"><bean-el:message key="ep.status" bundle="ep.messages"/>:*</td>

  <c:set var="parent" value="${epChannelEditView.map.parent.map}"/>
  <c:if test="${parent.status == 0}">
        <td class="labelField"><html-el:hidden property="status" value="0"/><bean-el:message key="ep.status.offline" bundle="ep.messages"/>
  </c:if>
  <c:if test="${parent.status == 1}">
    <c:if test="${epChannelEditView.map.isLeaf}">
        <td class="labelField"><html-el:radio property="status" value="1"/><bean-el:message key="ep.status.online" bundle="ep.messages"/>&nbsp;<html-el:radio property="status" value="0"/><bean-el:message key="ep.status.offline" bundle="ep.messages"/>
    </c:if>
    <c:if test="${not epChannelEditView.map.isLeaf}">
        <td class="labelField"><html-el:radio property="status" value="1"/><bean-el:message key="ep.status.online" bundle="ep.messages"/>&nbsp;<html-el:radio property="status" value="0"/><bean-el:message key="ep.status.offline.branch" bundle="ep.messages"/>&nbsp;<html-el:radio property="status" value="2"/><bean-el:message key="ep.status.online.branch" bundle="ep.messages"/>
    </c:if>
  </c:if>

        </td>
      </tr>

  <c:if test="${epChannelEditView.map.showNavigable}">
      <tr>
        <td class="label"><bean-el:message key="ep.navigable" bundle="ep.messages"/>:*</td>
        <td class="labelField">
		<html-el:radio property="navigable" value="0"/><bean-el:message key="ep.yes" bundle="ep.messages"/>
		<html-el:radio property="navigable" value="1"/><bean-el:message key="ep.no" bundle="ep.messages"/>
        </td>
      </tr>
  </c:if>

      <tr>
        <td class="label"><bean-el:message key="ep.channel.parent.channel" bundle="ep.messages"/>:*</td>
<c:set var="btnDisabled" value=""/>
<c:if test="${epChannelForm.map.parentType == 0}">
  <c:set var="btnDisabled">disabled="disabled"</c:set>
</c:if>
        <td class="labelField"><html-el:radio property="parentType" value="1" onclick="disableBrowseChannel(false)"/><bean-el:message key="ep.channel" bundle="ep.messages"/>&nbsp;<input type="text" name="parentName" size="30" value="<c:out value="${epChannelEditView.map.parent.map.name}"/>" onfocus="this.blur()">&nbsp;<input type="button" name="btnBrowseChannel" class="pageButton" value="<bean-el:message key="button.browse" bundle="ep.messages"/>" onclick="doChannelSelect()" <c:out value="${btnDisabled}"/>><br>
                               <html-el:radio property="parentType" value="0" onclick="disableBrowseChannel(true)"/><bean-el:message key="ep.root" bundle="ep.messages"/>
        </td>
      </tr>

      </table>

      <div class="pageButtonWrap" align="right">
        <input type="reset" name="resetBtn" value="<bean-el:message key='button.reset' bundle="ep.messages"/>" class="inputButton">
        &nbsp;&nbsp;
        <input type="button" name="cancelData" class="inputButton" value="<bean-el:message key='button.cancel' bundle="ep.messages"/>" onclick="doCancel(this.form)">
        <input type="submit" name="saveData" class="inputButton" value="<bean-el:message key='button.save' bundle="ep.messages"/>">
      </div>

      </html-el:form>

    </td>
  </tr>
</table>
